<template>
	<view>
		<u-sticky bgColor="#a3d8f5">
			<view class="mainpadding" :style="{paddingTop:menutop+'rpx'}">
				<view class="flexleft">
					<image src="@/static/image/system/hsz.png" class="hszclass" mode=""></image>
					<view class="xiaobai fonweight" style="font-size: 35rpx;">红十字基金会“孤寡老人大病救助基金”</view>
				</view>
				<view class="margin_top flexbetween">
					<u-icon name="arrow-left" color="#fff" size="24" @click="backpage()"></u-icon>
					<view class="xiaobai fonweight sanshier" style="font-size: 32rpx;">医疗申请补充资料</view>
					<image src="@/static/image/system/list.png" mode="" class="topliclass" @click="toplistfn"></image>
				</view>
			</view>
		</u-sticky>
		<view class="ffffff mainpadding">
			<view class="ershiba xiaohei fonweight">患者信息
				<text class="ershiba xiaohong fonweight">*</text>
			</view>
			<view class="margin_top xiahuaxian flexleft">
				<view class="ershiba xiaohei margin_right2">姓名</view>
				<input placeholder="请输入" type="text" v-model="name" />
			</view>
			<view class="margin_top xiahuaxian flexleft">
				<view class="ershiba xiaohei margin_right2">性别</view>
				<u-radio-group v-model="sex" placement="row" circle>
					<u-radio activeColor="#d41c19" :customStyle="{marginRight: '30rpx'}" label="男" name="1"></u-radio>
					<u-radio activeColor="#d41c19" label="女" name="2"></u-radio>
				</u-radio-group>
			</view>
			<!-- <view class="margin_top xiahuaxian flexleft">
				<view class="ershiba xiaohei margin_right2">年龄</view>
				<input placeholder="请输入" type="number" v-model="idCard" />
			</view> -->

			<view class="margin_top xiahuaxian flexleft">
				<view class="ershiba xiaohei margin_right2">手机号（+86）</view>
				<input placeholder="请输入手机号" type="number" v-model="tel" />
			</view>	
			<view class="margin_top flexleft">
				<view class="ershiba xiaohei margin_right2">家庭住址</view>
				<input placeholder="请输入" type="text" v-model="jtaddress" />
			</view>
		</view>
		
		<view class="ffffff mainpadding margin_top">
			<view class="ershiba xiaohei fonweight">检查结果
				<text class="ershiba xiaohong fonweight">*</text>
			</view>
			<view class="flexleft flex_wrap">
				<view class="flexcenter tpbox " v-for="(item,index) in images_text" :key="index">
					<view class="tjtp">
						<image class="tjtp" :src="item" mode=""></image>
						<view class="deleteimg" @click="delindex(index,images,images_text)"></view>
					</view>
				</view>
				<view class="flexcenter tpbox " @click="uploadImg(6,images,images_text)">
					<image class="tjtp" src="@/static/image/system/tjtp.png" mode=""></image>
				</view>
			</view>
			<view class="xiaohui ershiba margin_top">请上传检验报告或影像资料</view>
		</view>
		<view class="ffffff mainpadding margin_top">
			<view class="ershiba xiaohei fonweight">症状/病情
				<text class="ershiba xiaohong fonweight">*</text>
			</view>
			<textarea style="width: 100%;" class="margin_top textarea" placeholder="可简单描述您的症状或病情..." maxlength="-1" 
				v-model="bqdes"></textarea>
		</view>
		<view class="mainpadding">
			<view class="bigbtn" @click="submit()">加密提交</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				// #ifdef H5
				menutop: 80,
				// #endif
				// #ifdef MP-WEIXIN
				menutop: 0,
				// #endif	
				images: [],
				images_text: [],
				name:"",
				sex:"1",
				tel:"",
				jtaddress:"",
				bqdes:"",
				listid:""
			}
		},
		onLoad(options) {
			// #ifdef MP-WEIXIN
			this.menutop = uni.getMenuButtonBoundingClientRect().top * 2
			// #endif
			this.listid = options.id
			this.getDetail()
		},
		methods: {
			getDetail(){
				httpRequest.request('/api/user/ylapplyDetail', 'GET', {
					id: this.listid,
				}).then(res => {
					let data = res.data
					this.images = data.jcjg_images.split(',')
					this.images_text = data.jcjg_images_text
					this.name = data.name
					this.sex = data.sex
					this.tel = data.tel
					this.jtaddress = data.jtaddress
					this.bqdes = data.bqdes
				}).catch(err => {})
			},
			submit() {
				if (this.name == "") {
					httpRequest.toast("请输入姓名")
					return false
				}
				if (this.tel == "") {
					httpRequest.toast("请输入手机号")
					return false
				}
				if (this.jtaddress == "") {
					httpRequest.toast("请输入家庭地址")
					return false
				}
				if (this.images.length==0) {
					httpRequest.toast("请上传照片")
					return false
				}
				if (this.bqdes == "") {
					httpRequest.toast("请输入病情描述")
					return false
				}
				let url = "/api/user/ylapplyAgin"
				let data = {
					name: this.name,
					sex: this.sex,
					tel:this.tel,
					jtaddress:this.jtaddress,
					jcjg_images:this.images.join(),
					bqdes:this.bqdes,
					id:this.listid
				}
				httpRequest.request(url, 'GET', data).then(res => {
					httpRequest.toast(res.msg)
					if(res.code==1){
						setTimeout(()=>{
							uni.navigateBack(1)
						},1000)
					}
				})
			},
			uploadImg(value, upImgs, upImgs_text) { //上传图片
				let _this = this;
				uni.showActionSheet({
					itemList: ['相机', '相册'],
					success: function(res) {
						// 选择相机走0
						if (res.tapIndex == 0) {
							httpRequest.chooseImage(6, ['camera']).then(res => {
								for (var i = 0; i < res.length; i++) {
									_this.uploadImageService(res[i], upImgs, upImgs_text)
								}
							}).catch(err => {});
						}
						// 选择相册走1
						if (res.tapIndex == 1) {
							httpRequest.chooseImage(6, ['album']).then(res => {
								for (var i = 0; i < res.length; i++) {
									_this.uploadImageService(res[i], upImgs, upImgs_text)
								}
							}).catch(err => {});
						}
					},
					fail: function(res) {}
				});
			},
			delindex(index, upImg, upImgs_text) {
				upImg.splice(index, 1)
				upImgs_text.splice(index, 1)
			},
			uploadImageService(url, upImg, upImgs_text) {
				let _this = this;
				httpRequest.uploadFile('/api/common/upload', url).then(res => {
					let image_item = res.fullurl;
					upImg.push(res.url)
					upImgs_text.push(image_item);
				}).catch(err => {});
			},
		}
	}
</script>

<style>

</style>